package com.xg.frame.log.aop;//package com.xg.frame.log.aop;
//
//import com.alibaba.fastjson.JSON;
//import com.alibaba.fastjson.JSONObject;
//import com.xg.frame.constant.TraceConstant;
//import com.xg.frame.entity.ConstantCode;
//import com.xg.frame.entity.R;
//import com.xg.frame.exception.sqException;
//import com.xg.frame.log.annotation.LogAnnotation;
//import com.xg.frame.log.model.SysLog;
//import com.xg.frame.log.util.TraceUtil;
//import com.xg.frame.utils.UuidUtil;
//import lombok.extern.slf4j.Slf4j;
//import org.apache.commons.lang3.StringUtils;
//import org.aspectj.lang.ProceedingJoinPoint;
//import org.aspectj.lang.annotation.Around;
//import org.aspectj.lang.annotation.Aspect;
//import org.aspectj.lang.reflect.MethodSignature;
//import org.slf4j.MDC;
////import org.springframework.beans.factory.BeanFactory;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.core.annotation.Order;
//import org.springframework.stereotype.Component;
//
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//import java.util.ArrayList;
//import java.util.Date;
//import java.util.Enumeration;
//import java.util.List;
//import java.util.concurrent.ThreadLocalRandom;
//
///**
// * 日志AOP,标准日志格式logback-spring.xml
// * 如果开启日志记录，需要多数据配置
// * @author dehuisun
// *
// */
//@Component
//@Slf4j
//@Aspect
//@Order(-1) // 保证该AOP在@Transactional之前执行
//public class LogAnnotationAOP {
//
////	@Autowired
////    BeanFactory beanFactory;
//
//	@Around("execution(* com.xg.*.controller.*.*(..))")
//	public Object log(ProceedingJoinPoint joinPoint) throws Exception{
//		// 请求流水号
//		String traceId = StringUtils.defaultString(TraceUtil.getTrace(), MDC.get(TraceConstant.LOG_B3_TRACEID));
//		// 请求开始时间
//		long start = System.currentTimeMillis();
//		// 请求流水号
//		if (StringUtils.isEmpty(traceId)) {
//			traceId = UuidUtil.get32UUID();
//		}
//		// 请求方法
//		MethodSignature methodSignature = (MethodSignature) joinPoint.getSignature();
//		String url =  methodSignature.getDeclaringTypeName() + "/"+ methodSignature.getName();
//		//请求返回值
//		Object result = null;
//		//请求方法参数
//		Object[] args = joinPoint.getArgs();// 参数值
//
//		try {
//			log.info("开始请求：transid={},  url={} , params={}", traceId, url, args);
//			// 调用原方法
//			result = joinPoint.proceed();
//		}catch (sqException e) {
//			log.error("请求报错：transid={},  url={} ,error ={} ", traceId, url, e);
//			result = R.error().message(e.getMsg()).code(e.getCode());
//		}catch (Exception e) {
//			log.error("请求报错：transid={},  url={} ,error ={} ", traceId, url, e);
//			result = R.error();
//		} finally {
//			// 获取回执报文及耗时
//			String info="";
//			if(result instanceof R){
//				info = JSON.toJSONString(result);
//			}
//			log.info("请求完成：transid={}, 耗时={}, resp={}:", traceId, (System.currentTimeMillis() - start)+" ms",
//					result == null ? null : info);
//			return result;
//		}
//
//	}
//}
